<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="pu" uri="/WEB-INF/tld/pageutil.tld" %>
<%@taglib prefix="mu" uri="/WEB-INF/tld/mallutil.tld" %>
<%@taglib prefix="pageable" uri="/WEB-INF/tld/pageable.tld" %>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<c-rt:set var="imgDomain"><%=ServerValue.getImgDomain()%></c-rt:set>
<!-- 
<link rel="stylesheet" href="/css/yaodian100_header_v5.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/css/yaodian100_footer_v3.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/css/pdpagese_v3.css" type="text/css" media="screen,print" />
-->	
<script>
var isClicked=false;
$(function(){
	$('#wordCountDown').html(250-document.questionForm.questionContent.value.length);
	$("#iv").attr("original","<c-rt:url value="/servlet/imageValid.jpg"/>?"+Math.random());
	$("#changeValidImage").click(function(){
		$("#iv").attr("src","<c-rt:url value="/servlet/imageValid.jpg"/>?"+Math.random());
	});
	$("#questionContent").keyup(function(){
		if(document.questionForm.questionContent.value.length>250){
			alertDialog('商品问答', "已超过字数限制");
			$("#questionContent").val($("#questionContent").val().substring(0,250));
		}
		$('#wordCountDown').html(250-document.questionForm.questionContent.value.length);
	});
	$(":input[name='isMember'][type='radio']").click(function(){
		if($(this).val() == "true" && $(this).attr('checked') && !isLogin()){
			alertDialog('商品问答', '要发问请先登录!');
			$("#mail").attr("disabled","disabled");
			return;
		}else{
			$("#mail").attr("disabled","");
		}
	});
	$("#submit_button").click(function(){
		if($('#isMember').attr('checked') && !isLogin()){
			alertDialog('商品问答', '要发问请先登录!');
			return;
		}
		error='';
		if( document.questionForm.questionContent.value==''){
			error+="请填写问题内容！\r\n";
			alertDialog('商品问答',"请填写问题内容！");
		}else{
			if(document.questionForm.questionContent.value.length>250){
				error+="您已超过250的字数限制！\r\n";
				alertDialog('商品问答', '您已超过250的字数限制！');
			}
		}
		if(document.questionForm.validValue.value==''){
			error+="请输入验证码！\r\n";
			alertDialog('商品问答', '请输入验证码！');
		}
		for(i=0; i<document.questionForm.isMember.length; i++){
			if(document.questionForm.isMember[i].checked){
				if(document.questionForm.isMember[i].value=='false'){
					if(document.questionForm.email.value==''){
						error+="请填写您的email地址！\r\n";
						alertDialog('商品问答', '请填写您的email地址！');
					}
				}
			}
		} 
		if(error!=''){
			//alertDialog('讯息',error);
		}else{
			document.questionForm.submit();
		}
		return false;
	});
});
</script>
<div class="pd-box">
<a name="questionQAA"></a>
        <c-rt:if test="${!empty qeas}">
        <div class="page-accound"> 
        	<c-rt:url value="/product/product.do?productId=${param.productId}" var="qaaUrl"/>
          <p align="right">共${tp.totalRecords }笔：${tp.currentPage }/${tp.totalPages} 页 <pageable:Pageable formname="frontForm" url="${qaaUrl}"  escapeparams="productId" key="key" style="front"/></p> 
        </div> 
          <table class="qa-bg"> 
          <c-rt:forEach items="${qeas }" var="qea" varStatus="status">
          ${pu:reqSet('loginId', null) }
            <tr class="bg-yl"> 
              <td width="15%" valign="top"><div class="qa-pic-ask">问题${tp.totalRecords-((tp.currentPage-1)*tp.recordsizeperpage)-status.index }</div></td> 
              <td width="65%" valign="top"><p><strong>
              	<c-rt:if test="${!empty qea.question.memberId}">
              	${pu:reqSet('loginId', pu:get('com.yaodian100.ec.member.entity.Member', qea.question.memberId).loginId) }
              	${pu:maskString(loginId, 3) }
              	</c-rt:if>
              	<c-rt:if test="${empty qea.question.memberId}">
              	访客${pu:maskString(qea.question.email, 3) }
              	</c-rt:if>
              	：</strong></p> 
                ${qea.question.description }
              </td> 
              <td width="20%" valign="top" class="txt-time">[<fmt-rt:formatDate value="${qea.question.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>]</td> 
            </tr> 
           	<c-rt:set var="showQ" value="${false }"/>
           	<c-rt:set var="showAnswer" value="${false }"/>
           	<c-rt:forEach items="${qea.question.answers }" var="answer">
           		<c-rt:if test="${answer.showOnProductPage=='true' && answer.isApproved!=false}">
           		<c-rt:set var="showAnswer" value="${true }"/>
           		</c-rt:if>
           	</c-rt:forEach>
           	<c-rt:if test="${showAnswer}">
	            <c-rt:forEach items="${qea.question.answers}" var="answer" varStatus="answerI">
	            <c-rt:if test="${answer.showOnProductPage=='true'}">
	            <tr> 
	              <td valign="top">
	              <c-rt:if test="${!showQ}">
	              <c-rt:set var="showQ" value="${true}"/>
	              <div class="qa-pic-ans">回答</div>
	              </c-rt:if>
	              </td> 
	              <td valign="top" class="txt-gy-2">${answer.content }</td> 
	              <td valign="top" class="txt-time">[<fmt-rt:formatDate value="${answer.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>]</td> 
	            </tr> 
	            </c-rt:if>
	            </c-rt:forEach>
            </c-rt:if>
            <c-rt:if test="${!showAnswer}">
             <tr> 
	              <td valign="top">
	              
	              <div class="qa-pic-ans">回答</div>
	              
	              </td> 
	              <td valign="top" class="txt-gy-2">此问题的回答已设定为不显示</td> 
	              <td valign="top" class="txt-time"></td> 
            </c-rt:if>
          </c-rt:forEach>
          </table> 
  		  <div class="page-accound1"></div> 
          <p class="page-change">
          第${tp.currentPage }页，共${tp.totalPages}页<pageable:Pageable formname="pageableForm" url="${qaaUrl}" escapeparams="productId" key="key"/></p>
          <p class="to-top"><a href="#"><span class="a-top"></span>TOP</a></p> 
              </c-rt:if>
        <c-rt:if test="${empty qeas}">
        <div class="qa-bg"> 
        <p class="txt-noqa">目前没有任何问题！</p> 
      </div> 
        </c-rt:if>
        <div class="qa-service"> 
        <form name="questionForm" method="post" action="<c-rt:url value="/product/createQuestion.do#questionQAA"/>">
        <input type="hidden" name="productId" value="${product.productId }"/>
        <input type="hidden" name="ask" value="true"/>
          <h2>向商家发问</h2> 
          	<script>
				$(function(){
					$('.msg').hide();
					<c-rt:if test="${!empty sysMessage }">
					<c-rt:if test="${sysStatus=='1'}">
					setTimeout('delayDialog()', 1000);
					</c-rt:if>
					<c-rt:if test="${sysStatus=='0'}">
					$('.msg').show();
					</c-rt:if>
					</c-rt:if>
				});
				function delayDialog(){
					confirmDialog('商品问答', '${sysMessage}');
				}
          	</script>
          <c-rt:if test="${!mu:isLogined()}">
          <ul> 
          <li> 
            <input id="isMember" name="isMember" type="radio" value="true" checked="checked" /> 
            <%
            	request.setAttribute("application", application);
            %>
            <c-rt:set var="loginUrl">
            	/tologin.do?redirect_url=/product/product.do?productId=${product.productId }
            </c-rt:set>
            我是会员，我要<a href="javascript:;" onclick="loginForward();">登入后发问</a></li> 
          <li> 
            <input name="isMember" type="radio" value="false" /> 
            我不是会员 <span class="txt-gy">(回复将寄到您所提供的email)</span></li> 
          <li><span class="txt-inline"> 输入您的email：</span> 
            <input size="30" id="mail" name="email" value="${param.email }" disabled="disabled" /> 
          </li> 
        </ul> 
          </c-rt:if>
          <c-rt:if test="${mu:isLogined()}">
          <input name="isMember" type="hidden" value="true"/>
          	</c-rt:if>
          	<textarea name="questionContent" id="questionContent" cols="88" rows="5"><c-rt:if test="${sysStatus=='0'}">${param.questionContent }</c-rt:if></textarea> 
            <p class="qa-txtnote"><span class="txt-gy">还能输入 <span id="wordCountDown">250</span> 个字</span><span class="txt-rd"> (您提交的问题时只有商家看的到，商家回答后才会於页面上显示。)</span></p> 
            <p align="center"><span class="txt-code">验证码：</span><input name="validValue" size="20"  value="" /> <span><img src="${imgDomain}/images/none2.gif" original="" id="iv" name="iv"></span> <a href="javascript:;" id="changeValidImage">看不清？换张图片</a><span style="display:block; margin-left:195px;*margin-left:207px;"><span class="msg rn">验证码错误</span></span></p>
            <c-rt:if test="${mu:isLogined()}"><c-rt:set var="logincss" value="c-f"/></c-rt:if> 
            <p align="center" class="${logincss}"><a href="javascript:;" id="submit_button" class="btn-mid">提交</a></p>
        </form>
        </div>
        
 </div>